import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";
import {api} from "/@/views/assets/leaseContract/DbHtb.api";

const { createConfirm } = useMessage();

enum Api {
  list = '/assets.accountReceive/dbHire/list',
  save='/assets.accountReceive/dbHire/add',
  edit='/assets.accountReceive/dbHire/edit',
  deleteOne = '/assets.accountReceive/dbHire/delete',
  deleteBatch = '/assets.accountReceive/dbHire/deleteBatch',
  importExcel = '/assets.accountReceive/dbHire/importExcel',
  exportXls = '/assets.accountReceive/dbHire/exportXls',
  importFAPIAO = '/assets.accountReceive/dbHire/importFAPIAO',
  exportFAPIAO =  '/assets.accountReceive/dbHire/exportFAPIAO',
  exportForOpenFapiao = "/assets.accountReceive/dbHire/exportForOpenFapiao",
  getIfExportFapiao = "/assets.accountReceive/dbHire/getIfExportFapiao",
}
export const exportForOpenFapiao = Api.exportForOpenFapiao;
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;

export const getImportFAOPIAOUrl = Api.importFAPIAO;
export const getExportFAOPIAOUrl = Api.exportFAPIAO;
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({url: Api.list, params});

export const listNoThenToday = (params) =>{
  console.log(params)
  if(params.htbh && params.htbh.replaceAll("*","")=="") {
    params.htbh = undefined;
  }
  if(params.qymc && params.qymc.replaceAll("*","")=="") {
    params.qymc = undefined;
  }

  if(!params.htbh && !params.qymc && !params.sfyf && !params.bank && !params.billtype && !params.skqx_begin && !params.skqx_end){

    let yft = "";
    if((new Date().getMonth()+1)>=10){
      yft = ""+(new Date().getMonth()+1);
    }else{
      yft = "0"+(new Date().getMonth()+1);
    }


    let date = new Date().getFullYear()+"-"+yft+"-"
      let d =  new Date().getDate();
    let d1 = "";
    if(d<10){
      d1 = "0"+d;
    } else{
      d1 = ""+d;
    }
    date = date+d1;
    params.skqx_begin = date;
    params.skqx_end = date;
  }
  return defHttp.get({url: Api.list, params});
}


/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}


export const getIfExportFapiao = (params) => {
  let url = Api.getIfExportFapiao;
  return defHttp.get({url: url, params});
}
